package com.xh.bussiness.textbook.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xh.bussiness.textbook.bean.request.TextbookPracticeContentRequest;
import com.xh.bussiness.textbook.dao.TextbookPracticeContentMapper;
import com.xh.bussiness.textbook.model.TextbookPracticeContent;
import com.xh.bussiness.textbook.service.ITextbookPracticeContentService;
import com.xh.core.bean.XhPage;
import com.xh.core.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * <p>
 * 讲义练习试题表 服务实现类
 * </p>
 *
 * @author JQM
 * @since 2019-09-26
 */
@Service
public class TextbookPracticeContentServiceImpl extends BaseServiceImpl<TextbookPracticeContentMapper, TextbookPracticeContent> implements ITextbookPracticeContentService {
    @Override
    public XhPage queryTextbookPracticeContentPage(XhPage page, TextbookPracticeContentRequest bean) {
        QueryWrapper qw=new QueryWrapper<TextbookPracticeContent>();
        //拼装条件
        qw=prepareParams(bean, qw);

        return (XhPage) this.dao.selectPage(page,qw);
    }

    @Override
    public List queryTextbookPracticeContent(TextbookPracticeContentRequest bean) {
        QueryWrapper qw=new QueryWrapper<TextbookPracticeContent>();
        //拼装条件
        qw=prepareParams(bean, qw);

        return this.dao.selectList(qw);
    }

    @Override
    public void deleteByTextbookId(String textbookId) {
        this.dao.deleteByTextbookId(textbookId);
    }


    /**
     * 准备条件
     * @param bean
     * @param qw
     */
    private QueryWrapper prepareParams(TextbookPracticeContentRequest bean, QueryWrapper qw) {
        if(bean.getIds()!=null&&bean.getIds().length>0){
            qw.in("id",bean.getIds());
        }
        return qw;
    }
}
